package com.gx.smart.building.ui.swap.viewmodel

import android.app.Application
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.blankj.utilcode.util.ToastUtils
import com.gx.smart.base.BaseViewModel
import com.gx.smart.building.admin.ScheduleAppApiService
import com.gx.smart.lib.http.api.asynctask.CallBack
import com.huishi.gx.ib.grpc.lib.ib.admin.schedule.v1.AppScheduleRecordPlusResp

class WaitingSignViewModel(app: Application) : BaseViewModel(app) {
    private val QRCode: MutableLiveData<ByteArray> = MutableLiveData()

    //生成交接班二维码
    fun generateAppScheduleRecordQrCode(id: String): LiveData<ByteArray> {
        ScheduleAppApiService.getInstance().generateAppScheduleRecordQrCode(
            id,
            object : CallBack<AppScheduleRecordPlusResp>() {
                override fun callBack(result: AppScheduleRecordPlusResp?) {
                    if (result == null) {
                        ToastUtils.showLong("服务器超时")
                        return
                    }
                    val comResp = result.comResp
                    if (comResp.code == 100) {
                        QRCode.value = result.content.toByteArray()
                    } else {
                        handleServiceException(comResp)
                    }
                }
            })
        return QRCode
    }
}